package com.yuanxin.chooseimage.imagechoosemodule.bean;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import java.io.Serializable;

/**
 * 图片实体
 * Created by Nereo on 2015/4/7.
 */
public class Image implements Serializable {

    public String filePath;
    public String name;
    public long time;
    public int height;
    public int width;
    public int type;

    private void getSize() {
        Bitmap bitmap = BitmapFactory.decodeFile(filePath);
        if (bitmap != null) {
            width = bitmap.getWidth();
            height = bitmap.getHeight();
        }
    }

    public int getHeight() {
        if (height == 0) {
            this.getSize();
        }
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWidth() {
        if (width == 0) {
            this.getSize();
        }
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public Image(String path, String name, long time) {
        this.filePath = path;
//       // Log.i("FilePath=====>",FilePath);
        this.type = path.endsWith("mp4") ? 1 : 0;
        this.name = name;
        this.time = time;
        //getSize();
    }

    public Image(String path, int width, int height) {
        this.filePath = path;
        this.type = path.endsWith("mp4") ? 1 : 0;
        this.width = width;
        this.height = height;
    }

    public Image(String path) {
        this.filePath = path;
    }

    @Override
    public boolean equals(Object o) {
        try {
            Image other = (Image) o;
            return this.filePath.equalsIgnoreCase(other.filePath);
        } catch (ClassCastException e) {
            e.printStackTrace();
        }
        return super.equals(o);
    }
}
